/*************************************************************************
	> File Name: 002.midOrder_postOrder.cpp
	> Author: Maureen 
	> Mail: Maureen@qq.com 
	> Created Time: 四  6/24 18:40:28 2021
 ************************************************************************/

#include <iostream>
#include <cstring>
using namespace std;

//中序和后序遍历，输出先序遍历
char mid[105], post[105];

void func(int midl, int midr, int postl, int postr) {
    if (midl > midr) { //该树不存在
        return ;
    }
    if (midl == midr) { //树只有一个节点时就直接输出
        cout << mid[midl];
        return ;
    }

    char root = post[postr];
    int ind = midl;
    while (mid[ind] != root) {
        ind++;
    }
    cout << root; //先序，就先输出根节点
    func(midl, ind - 1, postl, postl + ind - midl - 1); //遍历左子树
    func(ind + 1, midr, postl + ind - midl, postr - 1); //遍历右子树
}

int main() {
    cin >> mid >> post;
    func(0, strlen(mid) - 1, 0, strlen(post) - 1);
    cout << endl;

    return 0;
}

/***
 * TestCase:
 * RLGBADI (中序)
 * RLGDIAB (后序)
 * BGLRAID (先序)
 */
